package com.support;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@ReadingConverter
public enum StringToLocalDateConverter implements Converter<String, LocalDate> {
    INSTANCE;

    @Override
    public LocalDate convert(String source) {
        // 下面这段代码是long类型的时间数据转换为LocalDate的代码
      /*  Instant instant = Instant.ofEpochMilli(source);
        ZoneId zoneId = ZoneId.systemDefault(); // Use the system default time zone
        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
        return localDate;*/
        return LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
}
